package com.sharp.authorization.annotation.auth;

import com.sharp.authorization.holder.TokenHolder;
import com.sharp.authorization.utils.token.AuthTokenUtil;
import com.sharp.kernel.constant.err.ErrCodeSys;
import com.sharp.kernel.validate.Validator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * Title: DefaultAuthRole
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2021/8/17 19:34
 */
@Slf4j
@Component
public class TokenAuthRole implements AuthRole {

    @Override
    public void validate(HttpServletRequest request) {
        String token = AuthTokenUtil.extractToken(request);
        Validator.assertNotBlank(token, ErrCodeSys.PA_DATA_NOT_EXIST, "token");
        TokenHolder.set(token);
    }
}
